package com.mathlearning.auth.repository;

import com.mathlearning.auth.entity.DiscussionTag;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface DiscussionTagRepository extends JpaRepository<DiscussionTag, Long> {
    
    // 根据讨论ID查询标签
    List<DiscussionTag> findByDiscussionId(Long discussionId);
    
    // 删除讨论的所有标签
    void deleteByDiscussionId(Long discussionId);
    
    // 获取热门标签（按使用次数排序）
    @Query("SELECT dt.tagName as name, COUNT(dt.id) as count " +
           "FROM DiscussionTag dt GROUP BY dt.tagName ORDER BY COUNT(dt.id) DESC")
    List<Map<String, Object>> findHotTags();
}








